﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace _4_1_Function
{
    class Program
    {
        public static int testInt = 1;

        static bool PrintMessage(string s)
        {
            Console.WriteLine("Message:" + s);
            return true;
        }

        static void PrintStar()
        {
            Console.WriteLine("*******************");
        }

        static int Sum(int a, int b)
        {
            return a + b;
        }

        static float Sum(float a, float b)
        {
            return a + b;
        }

        static int Sum(params int[] param)
        {
            int sum = 0;
            for (int i = 0; i < param.Length; i++)
                sum += param[i];
            return sum;
        }

        static int Max(int a=0, int b=0)
        {
            Console.WriteLine(a + " " + b);
            int i = 1;
            //int ret = 0;
            //ret = a > b ? a : b;
            /*
            if (a > b)
                ret = a;
            else
                ret = b;
            */
            //return ret;
            return a > b ? a : b;

            int j = 1;
            Console.WriteLine(j);
        }

        static double Func1(float x)
        {
            return 3 * x * x * x + 2 * x * x - 1;
        }

        static double Func2(float x)
        {
            return x * x + 2 * x + 1;
        }

        static bool IsPrime(int x)
        {
            for (int i = 2; i < x / 2; i++)
                if (x % i == 0)
                    return false;
            return true;
        }

        static int Gys(int a, int b, int c)
        {
            int r=0, ret = 0;
            if (a < b) { r = a; a = b; b = r; }
            r = r > c ? r : c;
            for (int i = r - 1; i >= 1; i--)
            {
                if (a % i == 0 && b % i == 0 && c % i == 0)
                {
                    ret = i;
                    break;
                }
            }
            return ret;
        }

        static bool IsSuShu(int x)
        {
            for (int i = 2; i < x; i++)
            {
                if (x % i == 0)
                    return false;
            }
            return true;
        }

        static bool GeDeBaHe(int x)
        {
            for (int i = 2; i < x; i++)
            {
                if (IsSuShu(i) && IsSuShu(x - i))
                {
                    Console.WriteLine("{0} = {1} + {2}", x, i, x - i);
                    return true;
                }
            }

            return false;
        }

        static int Age(int n)
        {
            if (n == 1)
                return 10;
            return Age(n - 1) + 2;
        }

        static int Fac(int n)
        {
            if (n == 0 || n == 1)
                return 1;
            return n * Fac(n - 1);
        }

        //abcdeedcba
        static void Recur(char c)
        {
            Console.Write(c);
            if (c < 'z')
                Recur((char)(c+1));
            Console.Write(c);
        }

        static void Testa()
        {
            int a = 2, b = 3, c = 5;
            Console.WriteLine(a +" " + b + " " + c);
            {
                int aa, bb = 2;
                aa = bb + c;
                Console.WriteLine(aa + " " + bb + " " + c);
            }
            c = a - b;
            Console.WriteLine(a + " " + b + " " + c);

        }


    static void Main(string[] args)
        {
#if IPONE

#elif ANDROID

#elif WINDOWS

#elif MAC

#else

#endif

#if DEBUG
            Console.WriteLine("-------- Debug");
#else
            Console.WriteLine("-------- UnDebug");
#endif

            Sum(12,34,56);
            Sum(12, 34);
            Sum(1);

            Max();
            Max(1);
            Max(2, 3);
            Console.ReadKey();
            //*****************************************
            Console.WriteLine(testInt);
            Console.WriteLine(Test.tsetInt);
            Test t = new Test();
            //t.intAAA = 1;

            Console.WriteLine(Program.Max(12, 13));
            Console.WriteLine(Test.Max(12, 13));

            Testa();
            //int i = 0;
            //****************recur****************
            Recur('a');

            Console.ReadKey();
            //****************Age****************
            Console.WriteLine("{0} Fac: {1}", 4, Fac(4));

            Console.ReadKey();

            //****************Age****************
            Console.WriteLine("第 {0} 人 {1} 岁。", 5, Age(5));

            Console.ReadKey();
            //****************GeDeBaHe****************
            for (int i = 6; i < 1000; i+=2)
            {
                if (GeDeBaHe(i) == false)
                    Console.WriteLine("哥德巴赫猜想是错的，哈哈哈！！！");
            }
            Console.ReadKey();
            //****************Gys****************
            Console.WriteLine(Gys(4, 6, 8));
            //****************IsPrime****************
            for (int i = 100; i <= 200; i++)
                if (IsPrime(i))
                    Console.WriteLine("{0} is Prime!", i);
            Console.ReadKey();
            //*****************Func******************
            Console.WriteLine("x= {0} Func1 :{1}", 111, Func1(111));
            Console.WriteLine("x= {0} Func2 :{1}", 111, Func2(111));
            Console.ReadKey();

            //*****************Max*******************
            var testVar = 1234;
            int max = Max(testVar, 4567);

            Console.WriteLine(Max(789, Max(1234, 4567)));
            PrintMessage(max.ToString());
            Console.ReadKey();

            //*****************Print Message******************
            PrintStar();
            bool flag = PrintMessage("auigujgjpsdoh;jp");
            PrintMessage(flag.ToString());
            PrintStar();

            Console.ReadKey();
        }
    }
}
